/**
 * 
 */
package com.tw.trips.domain;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.neo4j.graphdb.Direction;
import org.springframework.data.neo4j.annotation.Fetch;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;

/**
 * @author m1005264
 * 
 */
@NodeEntity
public class Location {

	public Location(String name) {
		this.name = name;
	}

	public Location() {
		super();
	}

	@GraphId
	Long nodeiD;

	@Indexed
	String name;

	@RelatedTo(type = "UPDATED", direction = Direction.BOTH)
	@Fetch
	private Set<Update> updates;

	public Long getNodeiD() {
		return nodeiD;
	}

	public void setNodeiD(Long nodeiD) {
		this.nodeiD = nodeiD;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Update> getUpdates() {
		return updates;
	}

	public Update update(String msg, String imgUrl, Date createdOn) {
		Update update = new Update(msg, imgUrl, createdOn);
		update.setForLocation(this);
		return update;
	}

	@Override
	public String toString() {
		return "Location [nodeiD=" + nodeiD + ", name=" + name + ", updates="
				+ updates + "]";
	}

	public Update postUpdate(String msg, String imgURL, Date createdOn,
			Traveller author) {
		Update updt = new Update(msg, imgURL);
		updt.setUpdatedBy(author);
		updt.setCreatedOn(createdOn);
		updt.setForLocation(this);
		if (this.updates == null)
			this.updates = new HashSet<Update>();
		// this.updates.add(updt);
		return updt;
	}

	public void addUpdate(Update update) {
		update.setForLocation(this);
	}

}
